<?php
final class inCookie extends inDirector {

	//cookie 中 user 键的结构 
	private $save = array( 
		'user' ,
		'u_id'  ,
		'auth' , 
		'auth_mailverify'
	) ; #'uid' ,#'password' ,

	public function _set( $relier = null ) {
		# Add Cookie[uid, username]
		Cookie::set( 'user', $relier['username'] , 12592000 ,'', '' , 0 ) ; //30 days   
		Cookie::set( 'u_id', $relier['u_id'] , 12592000 ,'', '' , 0) ; //30 days   
		return Cookie::set( 'auth', authcode( "{$relier[password]}\t{$relier[u_id]}", 'ENCODE' ), 12592000 ) ; //30 days   
	}

	public function _get( $relier = null ) {
		if ( Cookie::is_set( 'auth' ) ) {
			$auth = hstripslashes( explode( "\t", authcode( Cookie::get( 'auth' ), 'DECODE' ) ) ) ;
			list( $upwd, $uid ) = empty( $auth ) || count( $auth ) < 2 ? array( 
				'' , 
				'' 
			) : $auth ;
			$user = getInfoById('User', $uid); #TODO 获取用户信息
		}
		return isset( $user ) && ($user['password'] == $upwd) ? $user : '' ;
	}

	public function _clear( $relier = null ) {
		Cookie::clear( 'auth' ) ;
	}

	public function _delete( $relier = null ) {
		foreach ( $this->save as $key ) {
			Cookie::delete( $key ) ;
		}
	}
}